//
//  YYJLHomePageController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2016/12/26.
//  Copyright © 2016年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLHomePageController.h"
#import "EScrollerView.h"
#import "YYJLcurriculumCell.h"
#import "YYJLNewCell.h"
#import "YYJLNewShopCell.h"
#import "YYJLSearchController.h"
#import "YYJLMessageController.h"
//
#import "YYJLHallViewController.h"
#import "YYJLRuleController.h"
#import "YYJLNoticeController.h"
//
#import "YYJLNewShowViewController.h"
#import "YYJLNewShowDetailController.h"
//
#import "YYJLNewShopController.h"
#import "YYJLNewShopDetailController.h"
//
#import "YYJLFunnyAnswerController.h"

#import "YYJLMonthlyTestController.h"

#import "YYJLPersonalTestController.h"
//
#import "YYJLNewCurriculumController.h"
#import "YYJLVideoDetailController.h"
#import "YYJLGraphicDetailController.h"
@interface YYJLHomePageController ()<EScrollerViewDelegate,YYJLcurriculumCellDelegate>
{
    UIView*headerView;//头部view
    UIView*curriculumView;//课程
    UIView*newView;//新品
    UIView*newShopView;//新店
    UIScrollView*_scrollView;
    EScrollerView *_escrollView;//广告轮播图
    UIView  * blureyView;//覆盖层
    UIImageView  * tipView;//提示框
    
}
@end

@implementation YYJLHomePageController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    [self creatUI];
    [self addHeaderView];
    [self creatUIForCurriculum];
    [self creatUIForNew];
    [self creatUIForNewShop];
    
    _scrollView.contentSize=CGSizeMake(0, (headerView.height+curriculumView.height+newView.height+newShopView.height)+40*PER_HEIGHT);
    
    blureyView=[[UIView alloc]initWithFrame:self.view.bounds];
    blureyView.backgroundColor=[UIColorFromHex(0x000000) colorWithAlphaComponent:.4];
    [self.view addSubview:blureyView];
    blureyView.hidden=YES;
    [self.view sendSubviewToBack:blureyView];
    
    [self addTipView];
}
-(void)addTipView{
    
    blureyView.hidden=NO;
    [self.view bringSubviewToFront:blureyView];
    tipView =[[UIImageView alloc]initWithFrame:CGRectMake(37*PER_WIDTH, 160*PER_HEIGHT, SCREEN_WIDTH-74*PER_WIDTH, 350*PER_HEIGHT)];
    tipView.image=[UIImage imageNamed:@"img_jifen_pop"];
    tipView.userInteractionEnabled=YES;
    [blureyView addSubview:tipView];
    
    //新人专享
    UIImage * newImg=[UIImage imageNamed:@"新人专享"];//79*20
    UIImageView * new =[[UIImageView alloc]initWithFrame:CGRectMake(tipView.width/2-newImg.size.width/2*PER_WIDTH, 17*PER_HEIGHT, newImg.size.width*PER_WIDTH, newImg.size.height*PER_HEIGHT)];
    new.image=newImg;
    [tipView addSubview:new];
    //删除按钮
    UIButton *guanbiBtn=[MyControl createButtonWithFrame:CGRectMake(tipView.width-33*PER_WIDTH, 10*PER_HEIGHT, 23*PER_WIDTH, 23*PER_WIDTH) ImageName:@"ico_guanbi" Target:self Action:@selector(guanbi) Title:@""];
    [tipView addSubview:guanbiBtn];
    
    
    UILabel * tipLb=[MyControl createLabelWithFrame:CGRectMake(0, 65*PER_HEIGHT, tipView.width, 16*PER_HEIGHT) Font:16 Text:@"恭喜您, 获取了5积分" Color:BLACK_COLOR];
    tipLb.textAlignment=NSTextAlignmentCenter;
     NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:tipLb.text];
    [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                     TINK_COLOR, NSForegroundColorAttributeName,
                                     [UIFont fontWithName:HLT size:16*PER_WIDTH],NSFontAttributeName, nil]
                              range:NSMakeRange(8, 1)];
    
    tipLb.attributedText = attributedString;
    [tipView addSubview:tipLb];
    
    UILabel * sureLb=[MyControl createLabelWithFrame:CGRectMake(0, tipLb.bottom+10*PER_HEIGHT, tipView.width, 13*PER_HEIGHT) Font:13 Text:@"首次登陆此应用都可以获得5积分哦" Color:FEELT_COLOR];
    sureLb.textAlignment=NSTextAlignmentCenter;
    
    [tipView addSubview:sureLb];
    
    //知道了按钮
    UIButton * cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame=CGRectMake(55.5*PER_WIDTH, tipView.height-61*PER_HEIGHT, 190*PER_WIDTH, 36*PER_WIDTH);
    cancelBtn.layer.cornerRadius=cancelBtn.height/2;
    cancelBtn.backgroundColor=TINK_COLOR;
    cancelBtn.titleLabel.font=[UIFont fontWithName:HSGBW3 size:16];
    cancelBtn.titleLabel.font=[UIFont systemFontOfSize:16*PER_HEIGHT];
    [cancelBtn setTitle:@"知道了" forState:0];
    [cancelBtn setTitleColor:WHITE_COLOR forState:0];
    [cancelBtn addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [tipView addSubview:cancelBtn];
    
   
    
    
}
#pragma mark--知道了
-(void)cancelBtn{
    [tipView removeFromSuperview];
    blureyView.hidden=YES;
    [self.view sendSubviewToBack:blureyView];
}
-(void)guanbi{
    [tipView removeFromSuperview];
    blureyView.hidden=YES;
    [self.view sendSubviewToBack:blureyView];
}
#pragma mark--UI
-(void)creatUI{
    UIImage*leftImg=[UIImage imageNamed:@"ico_sousuo"];
    UIImageView*leftView=[[UIImageView alloc]initWithFrame:CGRectMake(0*PER_WIDTH, 11*PER_HEIGHT, leftImg.size.width*PER_WIDTH, leftImg.size.height*PER_HEIGHT)];
    leftView.image=leftImg;
    UITextField*searchTF=[MyControl createTextFieldWithFrame:CGRectMake(55*PER_WIDTH, 27*PER_HEIGHT, 265*PER_WIDTH, 30*PER_HEIGHT) placeholder:@"请输入关键字" passWord:NO leftImageView:leftView rightImageView:nil];
    searchTF.backgroundColor=UIColorFromHex(0xebebeb);

    
    UIView * bluryView=[[UIView alloc]initWithFrame:searchTF.frame];
    bluryView.tag=99;
    bluryView.backgroundColor=[UIColor clearColor];
    UITapGestureRecognizer*searchTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    bluryView.userInteractionEnabled=YES;
    [bluryView addGestureRecognizer:searchTap];
    [self.view addSubview:searchTF];
    [self.view addSubview:bluryView];
    //消息按钮
    UIButton * button =[UIButton buttonWithType:UIButtonTypeCustom];
                button.frame= CGRectMake(SCREEN_WIDTH-12*PER_WIDTH-40*PER_WIDTH, searchTF.top, 40*PER_WIDTH, 30*PER_WIDTH);
    [button setImage:[UIImage imageNamed:@"ico_xinxi"] forState:0];
    [button setTitle:@"消息" forState:0];

    [button addTarget:self action:@selector(message) forControlEvents:UIControlEventTouchUpInside];
   // button.backgroundColor=[UIColor redColor];
    button.titleLabel.font=[UIFont fontWithName:HSGBW3 size:8*PER_WIDTH];
    button.titleLabel.font=[UIFont systemFontOfSize:12*PER_WIDTH];
    [button setTitleColor:UIColorFromHex(0x999999) forState:0];
    button.imageEdgeInsets=UIEdgeInsetsMake(-15*PER_HEIGHT, 10*PER_WIDTH, 0, 0);
    button.titleEdgeInsets=UIEdgeInsetsMake(15*PER_HEIGHT, -20*PER_WIDTH, 0, 0);
    [self.view  addSubview:button];
    
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    _scrollView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:_scrollView];
    
    
}
#pragma mark--跳转消息界面
-(void)message{
    YYJLMessageController* message=[[YYJLMessageController alloc]init];
    [self.navigationController pushViewController:message animated:YES];
}
#pragma mark--新店加盟
-(void)creatUIForNewShop{
     newShopView=[[UIView alloc]initWithFrame:CGRectMake(0, newView.bottom+10*PER_HEIGHT, SCREEN_WIDTH, 259*PER_HEIGHT)];
    newShopView.backgroundColor=[UIColor whiteColor];
    [_scrollView addSubview:newShopView];
    //标题
    UILabel*title=[MyControl createLabelWithFrame:CGRectMake(24*PER_WIDTH, 15*PER_HEIGHT, 60*PER_WIDTH, 15*PER_HEIGHT) Font:15 Text:@"新店加盟"];
    title.textColor=UIColorFromHex(0x333333);
    [newShopView addSubview:title];
    //更多按钮
    UILabel*more=[MyControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-42*PER_WIDTH, 17*PER_HEIGHT, 30*PER_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"更多"];
    more.userInteractionEnabled=YES;
    more.tag=3000;
    UITapGestureRecognizer*tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [more addGestureRecognizer:tap];
    more.textColor=UIColorFromHex(0xbc0c16);
    [newShopView addSubview:more];
    for (int i=0; i<2; i++) {
        YYJLNewShopCell*cell=[[YYJLNewShopCell alloc]initWithFrame:CGRectMake(12*PER_WIDTH+i*180*PER_WIDTH, title.bottom+20*PER_WIDTH, 175*PER_WIDTH, 199*PER_HEIGHT)];
        UITapGestureRecognizer*tap3=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
        cell.userInteractionEnabled=YES;
        [cell addGestureRecognizer:tap3];
        cell.tag=3001+i;
        [newShopView addSubview:cell];
    }

}
#pragma mark--新品区域
-(void)creatUIForNew{
    newView=[[UIView alloc]initWithFrame:CGRectMake(0, curriculumView.bottom+10*PER_HEIGHT, SCREEN_WIDTH, 294*PER_HEIGHT)];
    newView.backgroundColor=[UIColor whiteColor];
    [_scrollView addSubview:newView];
    //标题
    UILabel*title=[MyControl createLabelWithFrame:CGRectMake(24*PER_WIDTH, 15*PER_HEIGHT, 60*PER_WIDTH, 15*PER_HEIGHT) Font:15 Text:@"新品展示"];
    title.textColor=UIColorFromHex(0x333333);
    [newView addSubview:title];
    //更多按钮
    UILabel*more=[MyControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-42*PER_WIDTH, 17*PER_HEIGHT, 30*PER_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"更多"];
    more.userInteractionEnabled=YES;
    more.tag=2000;
    UITapGestureRecognizer*tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [more addGestureRecognizer:tap];
    more.textColor=UIColorFromHex(0xbc0c16);
    [newView addSubview:more];
    for (int i=0; i<2; i++) {
        YYJLNewCell*cell=[[YYJLNewCell alloc]initWithFrame:CGRectMake(12*PER_WIDTH+i*180*PER_WIDTH, title.bottom+15*PER_WIDTH, 175*PER_WIDTH, 242*PER_HEIGHT)];
        UITapGestureRecognizer*tap2=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
        cell.tag=2001+i;
        cell.userInteractionEnabled=YES;
        [cell addGestureRecognizer:tap2];
        [newView addSubview:cell];
    }

    
}
#pragma mark---加载最新课程区域
-(void)creatUIForCurriculum{
    curriculumView=[[UIView alloc]initWithFrame:CGRectMake(0, headerView.bottom+10*PER_HEIGHT, SCREEN_WIDTH, 509*PER_HEIGHT)];
    curriculumView.backgroundColor=[UIColor whiteColor];
    //标题
    UILabel*title=[MyControl createLabelWithFrame:CGRectMake(24*PER_WIDTH, 15*PER_HEIGHT, 60*PER_WIDTH, 15*PER_HEIGHT) Font:15 Text:@"最新课程"];
    title.textColor=UIColorFromHex(0x333333);
    [curriculumView addSubview:title];
    //更多按钮
    UILabel*more=[MyControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-42*PER_WIDTH, 17*PER_HEIGHT, 30*PER_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"更多"];
    more.userInteractionEnabled=YES;
    more.tag=1000;
    UITapGestureRecognizer*tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [more addGestureRecognizer:tap];
    more.textColor=UIColorFromHex(0xbc0c16);
    [curriculumView addSubview:more];
    //图片加载区域
    UIView*imgView=[[UIView alloc]initWithFrame:CGRectMake(0, title.bottom+20*PER_WIDTH, SCREEN_WIDTH, 459*PER_HEIGHT)];
    [curriculumView addSubview:imgView];
    for (int i=0; i<6; i++) {
        int j=i%2;
        
             YYJLcurriculumCell*cell=[[YYJLcurriculumCell alloc]initWithFrame:CGRectMake(12*PER_WIDTH+j*180*PER_WIDTH, i/2*153*PER_HEIGHT, 171*PER_WIDTH, 133*PER_HEIGHT)];
        cell.tag=1001+i;
        UITapGestureRecognizer*tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
        [cell addGestureRecognizer:tap1];
        cell.delegate=self;
        cell.userInteractionEnabled=YES;
        cell.isVideo=YES;
        cell.isShop=NO;
        [imgView addSubview:cell];
        
        
    }
    [_scrollView addSubview:curriculumView];
}
#pragma mark---加载头部view
-(void)addHeaderView{
    headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 340*PER_HEIGHT)];
    //广告图
    
    headerView.backgroundColor=[UIColor whiteColor];
    if (!_escrollView) {
        _escrollView = [[EScrollerView alloc]initWithFrameRect:CGRectMake(0, 0, headerView.width, 140*PER_HEIGHT) ImageArray:@[] TitleArray:@[] changPic:YES];
        _escrollView.delegate = self;
    }
    NSArray*mutPicArr=@[@"banner",@"",@"banner",@"",@"banner"];
    
        [_escrollView loadDataImageArray:mutPicArr TitleArray:@[] changPic:YES];
    [headerView addSubview:_escrollView];
    
    //学习专区
    UIView*studyView=[[UIView alloc]initWithFrame:CGRectMake(0, 140*PER_HEIGHT, headerView.width, 200*PER_HEIGHT)];
  
    [headerView addSubview:studyView];
    NSArray*imageArr1=@[@"ico_xuexibeikao",@"ico_yuekao",@"ico_zhuanye",@"ico_mouni"];
    NSArray*imageArr2=@[@"ico_paihang",@"ico_guize",@"ico_quwei",@"ico_gonggao"];
    NSArray*title1=@[@"学习备考",@"月考",@"专业考试",@"模拟考试"];
    NSArray*title2=@[@"名人堂",@"积分规则",@"趣味答题",@"公告"];
    //第一批按钮
    for (int i = 0; i<4; i++) {
        UIButton*btn=[MyControl createButtonWithFrame:CGRectMake(29*PER_WIDTH+i*89*PER_WIDTH, 24*PERCEN_HEIGHT, 46*PER_WIDTH, 68*PER_WIDTH) ImageName:@"" Target:self Action:@selector(topBtn:) Title:@""];
        btn.tag=100+i;
        [studyView addSubview:btn];
        
        UIImageView*img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 46*PER_WIDTH, 46*PER_WIDTH)];
        img.image=[UIImage imageNamed:imageArr1[i]];
        [btn addSubview:img];
        
        UILabel*lab=[MyControl createLabelWithFrame:CGRectMake(0, img.bottom+9*PER_HEIGHT, img.width, 13*PER_HEIGHT) Font:11.5 Text:title1[i]];
        lab.textColor=UIColorFromHex(0x555555);
        lab.textAlignment=NSTextAlignmentCenter;
        [btn addSubview:lab];
        
    }
    //第二批按钮
    for (int i = 0; i<4; i++) {
        UIButton*btn=[MyControl createButtonWithFrame:CGRectMake(29*PER_WIDTH+i*89*PER_WIDTH, 200*PERCEN_HEIGHT, 46*PER_WIDTH, 68*PER_WIDTH) ImageName:@"" Target:self Action:@selector(topBtn:) Title:@""];
        btn.tag=104+i;
        [studyView addSubview:btn];
        
        UIImageView*img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 46*PER_WIDTH, 46*PER_WIDTH)];
        img.image=[UIImage imageNamed:imageArr2[i]];
        [btn addSubview:img];
        
        UILabel*lab=[MyControl createLabelWithFrame:CGRectMake(0, img.bottom+9*PER_HEIGHT, img.width, 13*PER_HEIGHT) Font:11.5 Text:title2[i]];
        lab.textColor=UIColorFromHex(0x555555);
        lab.textAlignment=NSTextAlignmentCenter;
        [btn addSubview:lab];
        
    }

    [_scrollView addSubview:headerView];
}
#pragma mark---播放视频
-(void)playVideoOnview:(YYJLcurriculumCell *)view withValue:(id)value{
    
}
#pragma mark---跳转学习专区
-(void)topBtn:(UIButton*)sender{
    if (sender.tag==104) {
        YYJLHallViewController*hall=[[YYJLHallViewController alloc]init];
        [self.navigationController pushViewController:hall animated:YES];
    }
    else if (sender.tag==105){
        YYJLRuleController * rule=[[YYJLRuleController alloc]init];
        [self.navigationController pushViewController:rule animated:YES];
    }else if (sender.tag==106){
        YYJLFunnyAnswerController * funny=[[YYJLFunnyAnswerController alloc]init];
        [self.navigationController pushViewController:funny animated:YES];
    }
    else if (sender.tag==107){
        YYJLNoticeController*notice=[[YYJLNoticeController alloc]init];
        [self.navigationController pushViewController:notice animated:YES];

    }else if (sender.tag==101){
        YYJLMonthlyTestController * month =[[YYJLMonthlyTestController alloc]init];
        [self.navigationController pushViewController:month animated:YES];
    }else if (sender.tag==102){
        YYJLPersonalTestController * test =[[YYJLPersonalTestController alloc]init];
        test.test=TestPersonal;
        [self.navigationController pushViewController:test animated:YES];
    }else if (sender.tag==103){
         YYJLPersonalTestController * test =[[YYJLPersonalTestController alloc]init];
        test.test=TestSimulator;
        [self.navigationController pushViewController:test animated:YES];
    }
}
#pragma mark--更多跳转
-(void)tap:(UITapGestureRecognizer*)tapView{
    UIView*view=tapView.view;
    if (view.tag==99) {
        YYJLSearchController *searcch=[[YYJLSearchController alloc]init];
        [self.navigationController pushViewController:searcch animated:YES];
        return;
    }else if (view.tag==2000){
        YYJLNewShowViewController* new=[[YYJLNewShowViewController alloc]init];
        [self.navigationController pushViewController:new animated:YES];
    }else if (view.tag==2001|view.tag==2002){
        YYJLNewShowDetailController * detail=[[YYJLNewShowDetailController alloc]init];
        [self.navigationController pushViewController:detail animated:YES];
    }else if (view.tag==3000){
        YYJLNewShopController * shop=[[YYJLNewShopController alloc]init];
        [self.navigationController pushViewController:shop animated:YES];
    }else if (view.tag ==3001|view.tag==3002){
        YYJLNewShopDetailController * detail=[[YYJLNewShopDetailController alloc]init];
        [self.navigationController pushViewController:detail animated:YES];
    }else if (view.tag==1000){
        YYJLNewCurriculumController * curriculnum=[[YYJLNewCurriculumController alloc]init];
        [self.navigationController pushViewController:curriculnum animated:YES];
    }else if (view.tag==1001|view.tag==1002){
        YYJLVideoDetailController * detail =[[YYJLVideoDetailController alloc]init];
        [self.navigationController pushViewController:detail animated:YES];
    }else if(view.tag==1003|view.tag==1004|view.tag==1005|view.tag==1006){
        YYJLGraphicDetailController * detail =[[YYJLGraphicDetailController alloc]init];
        [self.navigationController pushViewController:detail animated:YES];
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
